var url = 'http://localhost:8098/apiInterface/commodityvisitdata/visitdata.gif';
var ajaxUrl = '/apiInterface/commodityvisitdata/reportvisitdata';
export default {
	doTrack (vm, params) {
		console.group('埋点数据: ');
		console.log('params: ', params);
		let _params = {
			shopId: vm.shopId
		};
		if (vm.userInfo && vm.userInfo.userId) {
			_params['memberId'] = vm.userInfo.userId;
		}
		if (vm.userInfo && vm.userInfo.nickname) {
			_params['memberName'] = vm.userInfo.nickname;
		}
		Object.assign(_params, params);
		console.log('_params: ', _params);
		// 调接口
		vm.$https.post(ajaxUrl, _params, {
			// baseUrl: 'http://localhost:8098'
			baseUrl: 'http://shopappapi.yy12365.com'
		}).then((res) => {
			console.log(error)
		}).catch(error => console.log(error));
		console.groupEnd();
	},
	doTrackWithImage(vm, params) {
		console.group('埋点数据: ');
		console.log('params: ', params);
		let _params = {
			shopId: vm.shopId
		};
		if (vm.userInfo && vm.userInfo.userId) {
			_params['memberId'] = vm.userInfo.userId;
		}
		if (vm.userInfo && vm.userInfo.username) {
			_params['memberName'] = vm.userInfo.username;
		}
		Object.assign(_params, params);
		console.log('_params: ', _params);
		//拼接参数串
		let args = '';
		for (let i in _params) {
			if (args != '') {
				args += '&';
			}
			args += i + '=' + _params[i]; //将所有获取到的信息进行拼接
		}
		//通过伪装成Image对象，请求后端脚本
		var img = new Image(1, 1);
		var src = `${url}?args=` + encodeURIComponent(args);
		console.log("args: " + args);
		console.log("请求到的后端脚本为" + src);
		img.src = src;
		console.groupEnd();
	}
}
